home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 5.2 KB | 163 lines | [TEXT/MPS ] |
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- { UMenu.p }
- { Copyright © 1989-1990 by Apple Computer Inc. All rights reserved. }
-
- {[f-]}
- (*
- T H E O R Y O F O P E R A T I O N
-
- This is Larry Rosenstein's excellent unit: UMenu, that supports an
- object-oriented way of defining custom menus.
-
- Instead of writing a menu defproc, you simply create a subtype of TMenu
- and override certain methods. Not only is this easier to program,
- but this unit takes care of some of the housekeeping that a menu
- defproc would normally have to do.
- *)
- {[f+]}
-
- UNIT UMenu;
-
- INTERFACE
-
- USES
- { • MacApp}
- UMacApp,
- {}
- Errors;
-
- CONST
- kNoMenuItem = 0; { used to indicate that no item is selected
- }
-
- TYPE
-
- MenuColors = RECORD { a composite of the MCEntries }
- itemColor: RGBColor; { the foreground color to draw the item with
- (the color of the title if title or
- menubar) }
- backgroundColor: RGBColor; { the background color to draw the item with
- (the color of the menubar if title or
- menubar)}
- markColor: RGBColor; { the foreground color to draw the mark with
- (checkmarks, etc.) }
- commandColor: RGBColor; { the foreground color to draw the command
- key equivalent with (command-v for paste,
- etc).}
- END;
- MenuColorsPtr = ^MenuColors;
- MenuColorsHandle = ^MenuColorsPtr;
-
- TMenu = OBJECT (TView)
- fMenuHandle: MenuHandle; { handle to menu itself }
- fFlashInterval: LONGINT; { Time (in ticks) between flashes of item
- highlighting; default is -1 which means
- only change highlighting w when item
- changes }
- fNextFlash: LONGINT; { Used internally }
- fMenuRect: Rect; { menuRect that was last passed to the MDef
- }
- fHitPt: Point; { hitPt that was last passed to the MDef.
- gets offset in Focus. }
- fHighlighted: BOOLEAN; { True if an item is highlighted }
- fBorder: Rect; { Added to menuRect to get actual hit rect;
- FindItem will not be called if the mouse
- is in the border. }
-
- { Initialization }
-
- PROCEDURE TMenu.IMenu(rsrcID: INTEGER;
- menuWidth, menuHeight: INTEGER);
- { IMenu reads the menu and sets up the MenuHandle and defproc
- so that the Menu Manager can communicate with the TMenu object.
- }
-
- { Menu Definition; all these methods must be overridden }
-
- FUNCTION TMenu.FindItem(hitPt: Point): INTEGER;
- { This is called to convert a point to an item number. }
-
- PROCEDURE TMenu.Highlight(whichItem: INTEGER;
- turnItOn: BOOLEAN);
- { Given an item number as returned by FindItem, this is called
- to highlight the item. This will not be called with
- whichItem = kNoMenuItem. }
-
- { Other methods }
-
- PROCEDURE TMenu.GetMenuColors(theMenu, theItem: INTEGER;
- VAR theMenuColors: MenuColors);
- { Called to get the appropriate menu colors for the menu and item.
- If the menu and item are 0 then info is for the menubar.
- If item is 0 then info is for the menu title.
- Attempts to return best guess at colors based on all available info. }
-
- FUNCTION TMenu.IsItemEnabled(item:INTEGER): Boolean;
- { Returns the enabled status of an item }
-
- PROCEDURE TMenu.UpdateHighlight(oldItem, newItem: INTEGER);
- { Called to update menu item highlighting. }
-
- { Private }
-
- PROCEDURE TMenu.HandleDefproc(message: INTEGER;
- theMenu: MenuHandle;
- VAR menuRect: Rect;
- hitPt: Point;
- VAR whichItem: INTEGER);
- { This is called by the custom defproc; it does a CASE
- on the message and calls 1 or more of the methods above. }
-
- PROCEDURE TMenu.HandleChooseMessage(message: INTEGER;
- theMenu: MenuHandle;
- VAR menuRect: Rect;
- hitPt: Point;
- VAR whichItem: INTEGER);
- { Called by the message dispatcher when a choose message has been sent }
-
- PROCEDURE TMenu.HandleDrawMessage(message: INTEGER;
- theMenu: MenuHandle;
- VAR menuRect: Rect;
- hitPt: Point;
- VAR whichItem: INTEGER);
- { Called by the message dispatcher when a draw message has been sent }
-
- PROCEDURE TMenu.HandleSizeMessage(message: INTEGER;
- theMenu: MenuHandle;
- VAR menuRect: Rect;
- hitPt: Point;
- VAR whichItem: INTEGER);
- PROCEDURE TMenu.HandlePopUpMessage(message: INTEGER;
- theMenu: MenuHandle;
- VAR menuRect: Rect;
- hitPt: Point;
- VAR whichItem: INTEGER);
- { Focusing Methods }
-
- FUNCTION TMenu.Focus: BOOLEAN; OVERRIDE;
-
- FUNCTION TMenu.FocusOnSuperView: BOOLEAN; OVERRIDE;
-
- { Misc. Methods }
-
- FUNCTION TMenu.GetGrafPort: GrafPtr; OVERRIDE;
-
- { Debugging Methods }
-
- PROCEDURE TMenu.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
-
- END;
-
- PROCEDURE InitUMenu;
- { Call this at the start of your program, before creating any TMenu objects.
- This can signal Failure. }
-
- IMPLEMENTATION
-
- {$I UMenu.inc1.p}
-
- END.
-